package com.tanhua.app.controller;

import com.tanhua.app.Service.TanhuaService;
import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.pojo.UserInfo;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.POST;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    //今日佳人
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }

    //GET /tanhua/recommendation
    // 推荐朋友
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto recommendUserDto) {

        PageResult<TodayBest> pageResult = tanhuaService.recommendation(recommendUserDto);
        return ResponseEntity.ok(pageResult);
    }
    //GET/tanhua/:id/personalInfo
    //根据用户id查询佳人详细信息
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity todayBestByid(@PathVariable("id") Long id){
      TodayBest todayBest= tanhuaService.todayBestByid(id);
      return ResponseEntity.ok(todayBest);
    }

    //GET/tanhua/strangerQuestions
    //查询陌生人问题
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId){
      String questions=  tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(questions);
    }
   // POST/tanhua/strangerQuestions
    //回复陌生人信息
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyQuestions(@RequestBody Map map) {
        //前端传递的userId:是Integer类型的
        String obj = map.get("userId").toString();
        Long userId = Long.valueOf(obj);
        String reply = map.get("reply").toString();
        tanhuaService.replyQuestions(userId,reply);
        return ResponseEntity.ok(null);

    }

    //GET/tanhua/cards
    //探花-左滑右滑（推荐探花用户列表）
    @GetMapping("/cards")
    public ResponseEntity cards(){
      List<TodayBest> list= tanhuaService.queryCardsList();
      return ResponseEntity.ok(list);
    }

    //GET/tanhua/:id/love
    //探花喜欢
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") Long id){
      tanhuaService.love(id);
return ResponseEntity.ok(null);
    }

    /**
     * 不喜欢
     */
    @GetMapping("{id}/unlove")
    public ResponseEntity<Void> notLikeUser(@PathVariable("id") Long likeUserId) {
        this.tanhuaService.notLikeUser(likeUserId);
        return ResponseEntity.ok(null);
    }
    /**
     * 搜附近
     */
    @GetMapping("/search")
    public ResponseEntity<List<NearUserVo>> queryNearUser(String gender,
                                                          @RequestParam(defaultValue = "2000") String distance) {
        List<NearUserVo> list = this.tanhuaService.queryNearUser(gender, distance);
        return ResponseEntity.ok(list);
    }
}